package br.eti.robsonfranca.clf4j.impl;

import br.eti.robsonfranca.clf4j.interfaces.Console;
import br.eti.robsonfranca.clf4j.interfaces.UITools;

import com.google.inject.Inject;

public class BasicUI implements UITools {

	private final Console console;
	
	@Override
	public void box(int left, int top, int width, int height) {
		int right = left + width - 1;
		int bottom = top + height - 1;
		horLine(left+1,top, width - 2);
		horLine(left+1,bottom, width - 2);

		verLine(left, top+1, height - 2);
		verLine(right, top+1, height - 2);
		
		console.gotoxy(left, top);
		console.printf("+");

		console.gotoxy(left, bottom);
		console.printf("+");
		
		console.gotoxy(right, top);
		console.printf("+");

		console.gotoxy(right, bottom);
		console.printf("+");

	}

	@Override
	public void fillBox(int left, int top, int width, int height) {
		// TODO Auto-generated method stub
		box(left,top,width,height);
		for(int j=1;j<height-1;j++) {
			for (int i=1;i<width-1;i++) {
				console.gotoxy(left+i, top+j);
				console.printf(" ");
			}
		}
	}

	@Override
	public void horLine(int left, int top, int width) {
		int j = left+width;
		for(int i=left;i<j;i++) {
			console.gotoxy(i, top);
			console.printf("-");
		}
	}

	@Override
	public void verLine(int left, int top, int height) {
		int j = top+height;
		for(int i=top;i<j;i++) {
			console.gotoxy(left, i);
			console.printf("|");
		}
	}

	@Inject
	public BasicUI(Console console) {
		this.console = console;
	}
	
}
